#ifndef STEP_H_
#define STEP_H_
#include<cmath>
#include<iostream>
//步长函数

class Step{
private:
    double m_h_min, m_h_max;//最小网格、最大网格
    double ma_1, ma_2, ma_e;//增长因子(一次，二次, e指数)
    int Nr;                 //网格数
    int m_step_type;
    double stepping(int n);    
public:
    explicit Step(int step_type, double h_min, double h_max, int nr){ 
        m_step_type = step_type;
        m_h_min = h_min;
        m_h_max = h_max;
        Nr = nr;
        
        ma_1 = 0.;
        ma_2 = (m_h_max - m_h_min)/double(Nr);
        ma_e = std::log(m_h_max / m_h_min) / double(Nr);
        

    }
    virtual ~Step(){

    }

    void operator()(double *step_array);

};

double Step::stepping(int n){
    
    double h_n;
    switch (m_step_type)
    {
    case 1:
        h_n = m_h_min;
        break;

    case 2:
        h_n = m_h_min + ma_2 * n;
        break;

    case 3:
        h_n = m_h_min * std::exp(ma_e * n);
        break;

    default:
        std::cout << "无效stepping function" << std::endl;
    }

    return h_n;
   
}

void Step::operator()(double *step_array){
    for(int i = 0; i < Nr; i++){
        step_array[i] = stepping(i);
    }
}

#endif